package cn.itcast.web.sevlet;

import cn.itcast.domain.Student;
import cn.itcast.service.impl.BaseServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

@WebServlet("/findStudentServlet")
public class FindStudentServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ArrayList<Student> students = new BaseServiceImpl().findAllStudent();

        System.out.println("students = " + students);

        if (students.size() != 0) {// 说明有学生信息
            request.getSession().setAttribute("studens",students);
            response.sendRedirect(super.getServletContext().getContextPath()+"/findStudent.jsp");
        }
    }
}
